﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GCExample
{
    class Program
    {
        static WeakReference SmallObjRef;
 static WeakReference LargeObjRef;
        static void Main(string[] args)
        {
            SetValues();
            GC.Collect(0);
            Console.WriteLine("GC.Collect(0)");
            Console.WriteLine("SmallObjRef.Target == null? {0}", SmallObjRef.Target == null);
            Console.WriteLine("LargeObjRef.Target == null? {0}\n", LargeObjRef.Target == null);
    
             GC.Collect(1);
             Console.WriteLine("GC.Collect(1)");
             Console.WriteLine("LargeObjRef.Target == null? {0}\n", LargeObjRef.Target == null);
  
             GC.Collect(2);
             Console.WriteLine("GC.Collect(2)");
             Console.WriteLine("LargeObjRef.Target == null? {0}\n", LargeObjRef.Target == null);
             Console.ReadKey();
        }
        static void SetValues()
        {
            SmallObjRef = new WeakReference(new byte[84000]);
            LargeObjRef = new WeakReference(new byte[85000]);
        }  
    }
}
